﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace PasswordManager.Src.DAO
{
    public class PasswordManagerDataContext:DataContext
    {
        private static string ConnectionString = "Data Source=isostore:/PasswordManager.sdf";
        public PasswordManagerDataContext():base(ConnectionString)
        {

        }
        public static void CreateDB()
        {
            using (PasswordManagerDataContext db =new PasswordManagerDataContext())
            {
                //db.DeleteDatabase();
                if (!db.DatabaseExists())
                {
                    db.CreateDatabase();
                    
                }
                if(db.AppSettinges.Count()==0)
                {
                    db.AppSettinges.InsertOnSubmit(new AppSetting { Language = "en-US" });
                    db.SubmitChanges();
                }
                if (db.PasswordCategories.Count() == 0)
                {
                    db.PasswordCategories.InsertOnSubmit(new PasswordCategory {Name="h"});
                    db.PasswordCategories.InsertOnSubmit(new PasswordCategory { Name = "hsafas" });
                    db.SubmitChanges();
                }
            }
        }
        public Table<PasswordCategory> PasswordCategories;
        public Table<PasswordDetail> PasswordDetails;
        public Table<AppSetting> AppSettinges;
    }
}
